package com.example.idempotency.controller;

import com.example.idempotency.annotation.Idempotent;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
public class MessageController {

    private final RabbitTemplate rabbitTemplate;

    @PostMapping("/send")
    @Idempotent(expireSeconds = 60)
    public ResponseEntity<String> send(@RequestBody String message) {
        rabbitTemplate.convertAndSend("my.exchange", "my.routing.key", message);
        return ResponseEntity.ok("Message sent.");
    }
}